package com.wiseman.writing;

import java.util.List;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.wiseman.writing.utility.BSJavaApi;
import com.wiseman.writing.utility.StrokeData;


public class StrokeSeqAdapter extends BaseAdapter implements ConstValue{

	private Context mContext;
	private BSJavaApi mBSAPi = null;
	private int mFontSize = 64;	

	private List<StrokeData> mStrokeDataList = null;

	public StrokeSeqAdapter(Context context, char c) {
		super();
		mContext = context;
		
		mBSAPi = new BSJavaApi(context, 1, BSFTABTYPE_UNICODEBYGB);
		
		if(mBSAPi.prepareData(c)){
			Log.d("stroke_order", "prepareData() error!");	
		}
		
		mStrokeDataList = mBSAPi.getCharData(mFontSize);							
	}
	

	public int getCount() {
		return mStrokeDataList == null?0:mStrokeDataList.size();
	}

	@Override
	public Object getItem(int index) {

		return index;
	}

	@Override
	public long getItemId(int index) {
		return index;
	}

	@Override
	public View getView(int index, View convertView, ViewGroup parent) {

		StrokeSeqView view = null;
		if (convertView == null) {
			convertView = new StrokeSeqView(mContext);			
		}
		
		
		view = (StrokeSeqView) convertView;
		view.setStrokeSequece(mStrokeDataList.subList(0, index+1), mFontSize);
		view.setImageResource(R.drawable.stroke_demo);		
		
		return convertView;
	}

}
